import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 15085202591
 * Date: 2022-11-23
 * Time: 11:46
 */
abstract class Shape {
    // 求面积
    public abstract double getArea();
    // 求周长
    public abstract double getPerimeter();
    // 偏移值--在面积和周长真实值基础上加上偏移值进行安全处理
    protected double offset;
    public void setOffset(double offset) {
        this.offset = offset;
    }
    public double getOffset() {
        return offset;
    }
}
class ShapeOperation {
    public static double getAreaOperation(Shape shape) {
        return shape.getArea();
    }
    public static double getPerimeterOperation(Shape shape) {
        return shape.getPerimeter();
    }
}

class Triangle extends Shape{
    private double a;
    private double b;
    private double c;

    public Triangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    @Override
    public double getArea() {
        double p = (a+b+c)/2.0;
        double area=Math.sqrt(p * (p - a) * (p - b) * (p - c));
        return area;
    }

    @Override
    public double getPerimeter() {
        return a + b + c;
    }
}

class Rectangle extends Shape{
    private double high;
    private double width;

    public Rectangle(double high, double width) {
        this.high = high;
        this.width = width;
    }

    @Override
    public double getArea() {
        return high * width;
    }

    @Override
    public double getPerimeter() {
        return (high + width) * 2;
    }
}

class  FormatOutput{
    private double area;
    private double perimeter;
    private String ShapeType;

    public void setArea(double area) {
        this.area = area;
    }

    public void setPerimeter(double perimeter) {
        this.perimeter = perimeter;
    }

    public void setShapeType(String s) {
        this.ShapeType = s;
    }

    public FormatOutput(String s, double area, double perimeter) {
        this.ShapeType = s;
        this.area = area;
        this.perimeter = perimeter;
    }
    public String getOutputValue(){
        String s1 = String.format("%.2f",area).toString();
        String s2 = String.format("%.2f",perimeter).toString();
        return ShapeType + "面积为:" + s1 + ",周长为:" + s2;
    }
}




public class Main5 {
    //不管是面积还是周长数据，都要求保留小数点后2位，故定义了类FormatOutput来实现输出数据格式的统一
    //现需要求解三角形和长方形的面积和周长

    public static void main(String[] args) {

        // a,b,c用于存储三角形的三条边
        double a, b, c;

        // length,width用于存储长方形的长和宽
        double length, width;

        // area,perimeter用于存储面积和周长
        double area, perimeter;

        // 获取三角形的三条边
        Scanner reader = new Scanner(System.in);
        a = reader.nextDouble();
        b = reader.nextDouble();
        c = reader.nextDouble();

        // 获取长方形的长和宽
        length = reader.nextDouble();
        width = reader.nextDouble();

        // 求三角形的面积和周长
        Shape shape = new Triangle(a, b, c);
        area = ShapeOperation.getAreaOperation(shape);
        perimeter = ShapeOperation.getPerimeterOperation(shape);

        // 格式化输出，保留小数点后2位数据
        FormatOutput formatOutput = new FormatOutput("三角形", area, perimeter);
        System.out.println(formatOutput.getOutputValue());

        // 求长方形的面积和周长
        shape = new Rectangle(length, width);
        area = ShapeOperation.getAreaOperation(shape);
        perimeter = ShapeOperation.getPerimeterOperation(shape);
        formatOutput.setShapeType("长方形");
        formatOutput.setArea(area);
        formatOutput.setPerimeter(perimeter);
        System.out.println(formatOutput.getOutputValue());

    }

}
